package com.ruhaly.demo01.common;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component //注入依赖
public class LogAspect {

    @Pointcut("execution(* com.ruhaly.demo01.service.UserServiceImpl.*(..))")
    public void logAop() {
        System.out.println("LogAspect");
    }


    @Before("logAop()")
    public void logBefore(JoinPoint joinPoint) {
        System.out.println(joinPoint.getArgs()[0] + "前置通知Before");
    }

    @After("logAop() && args(name,pwd)")
    public void logAfter(String name, String pwd) {
        System.out.println(name + pwd + "后置通知After");
    }

    @AfterReturning("logAop()")
    public void logAfterReturning() {
        System.out.println("返回通知AfterReturning");
    }

    @AfterThrowing("logAop()")
    public void logAfterThrow() {
        System.out.println("异常通知AfterThrowing");
    }
}
